#include "StdAfx.h"
#include "ODCombo.h"


// ODCombo.cpp : implementation file
//


// CODCombo

IMPLEMENT_DYNAMIC(CODCombo, CComboBox)

CODCombo::CODCombo()
{
}

CODCombo::~CODCombo()
{
}


BEGIN_MESSAGE_MAP(CODCombo, CComboBox)
END_MESSAGE_MAP()


// CODCombo message handlers


void CODCombo::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	// TODO:  Add your code to draw the specified item
	CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

	switch (lpDrawItemStruct->itemAction)
	{
	case ODA_DRAWENTIRE:
	case ODA_SELECT:
		{
			CBrush brush;

			if (lpDrawItemStruct->itemState & ODS_DISABLED)
			{
				brush.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
			}
			else if (lpDrawItemStruct->itemState & ODS_SELECTED)
			{
				brush.CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
			}
			else
			{
				brush.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
			}

			// Paint background
			pDC->FillRect(&lpDrawItemStruct->rcItem, &brush);
			brush.DeleteObject();

			// Print color rectangle
			if (lpDrawItemStruct->itemID != -1)
			{
				pDC->TextOut(lpDrawItemStruct->rcItem.left+5, lpDrawItemStruct->rcItem.top+5, m_strArray.GetAt(lpDrawItemStruct->itemData));
			}
		}

		if (!(lpDrawItemStruct->itemState & ODS_FOCUS))
			break;

		// Else fall through

	case ODA_FOCUS:
		// Draw focus rectangle
		pDC->DrawFocusRect(&lpDrawItemStruct->rcItem);
		break;
	}
}

int CODCombo::addString(LPCTSTR pText)
{
	int nItem = AddString(pText);
	if (nItem != CB_ERR)
	{
		m_strArray.Add(pText);
		SetItemData(nItem, nItem);
	}

	return nItem;
}
